from CSVUtils.utils import read_csv
from gupiao.code_info import generate_info
from gupiao.day_details import get_details


def random_sleep():
    import time
    import random
    time.sleep(random.random() * 2 + 0)

def select_data():
    data = read_csv('output-2021-09-09.csv')
    # print(data)
    code_list = []
    for row in data:
        # 筛选跟随人数和市盈率和价格
        if row[-1] != 'None' and row[8] != 'None' and (float(row[8])) < 15 and row[2] != 'None' and (float(row[2])) < 15:  # and row[1][0:3]!='*ST':
            code_list.append(row[0])
    return code_list


if __name__ == '__main__':
    code_list = select_data()
    print(len(code_list))
    dict1 = generate_info()

    count = 0
    for code in code_list:
        up_num_5, up_num_10, up_num_20, up_num_30 = get_details(code)
        if up_num_5 >= 4 and up_num_10 <= 6 and up_num_30 <= 15:
            print(code, dict1[code])
        #     count += 1
        # if count % 5 == 0:
        #     random_sleep()
        # if up_num_5 <= 3 and up_num_10 <= 5 and down_num_20 >= 13:
        #     print(code, dict1[code])
        count += 1
        if count % 10 == 0:
            random_sleep()
    print(code)